#ifndef _H_ARRAY_H__
#define _H_ARRAY_H__

#include "linux_def.h"
#include "core.h"

struct array_s {
    void	*elts;
    int		nelts;
    size_t	size;
    int		nalloc;
    pool_t	*pool;
};


array_t *array_create(pool_t *p, int n, size_t size);
void array_destroy(array_t *a);
void *array_push(array_t *a);
void *array_push_n(array_t *a, int n);


static inline int array_init(array_t *array, pool_t *pool, int n, size_t size)
{
    array->nelts = 0;
    array->size = size;
    array->nalloc = n;
    array->pool = pool;

    array->elts = palloc(pool, n * size);
    if (array->elts == NULL) {
        return E_FAIL;
    }

    return E_OK;
}

#endif
